---
title: Development and characterization of microsatellite markers for the tsetse species
  Glossina brevipalpis and preliminary population genetics analyses
author: "Fabian Gstöttenmayer1, Percy Moyaba1,2, Montse Rodriguez1, Fernando C. Mulandane3,
  Hermogenes N. Mucache4, Luis Neves3,4, Chantel De Beer1, Sophie Ravel5, Thierry
  De Meeus5, Philippe Solano5 Robert L. Mach6, Marc J. B. Vreysen1 and Adly M.M. Abd-Alla1*"
date: "2023-06-20"
output:
  pdf_document: default
  html_document:
    df_print: paged
  word_document: default
---

```{}
setwd("C:/Users/GSTOTTENMF/OneDrive - IAEA/Desktop/Manuscript V7/Submission/Data_repository")

library(ggplot2)
library(MASS)
library(rmarkdown)
library(knitr)
library(lme4)
library(MuMIn)
library(ggthemes) 
library(datasets)
library(plyr)
library(dplyr)
library(tidyverse)
library(coin)
```

```{r }
### Analysis of all loci on all samples
### Linkage disequilibrium: BY correction for all loci 
p.adjust(c(0.3229,	0.5156,	1,	0.001,	0.6289,	0.8639,	0.7811,	0.8109,	0.8749,	0.3022,	0.6471,	0.1094,	0.0072,	0.0763,	0.0103,	0.079,	0.9676,	0.2757,	0.1998,	0.544,	0.5839,	0.0206,	0.3982,	0.2224,	1,	0.9607,	0.3872,	0.1506,	0.4215,	0.2636,	1,	0.4142,	0.5945,	0.2685,	0.3466,	0.0648,	0.4681,	0.5652,	0.8601,	0.4104,	0.3353,	0.8572,	0.4667,	0.8822,	0.6735), method = "BY")


```

```{r }
### Correlation between FIS and FST for all loci on all samples
FISFST <- read.csv("FISFST_allloci_allsamples.csv", sep=",", row.names=NULL)
FISFST
with(FISFST, cor.test(FST, FIS, alternative="greater", method="spearman"))

```

```{r }
### Correlation between FIS and number of blanks for all loci on all samples
FISblanksall <- read.csv("FISblanks_allloci_allsamples.csv", sep=",", row.names=NULL)
FISblanksall
with(FISblanksall, cor.test(Nb, FIS, alternative="greater", method="spearman")) 
### Correlation between FIS and number of blanks for 7 loci (Gb5, 28, 35, 66, 73, 92, 165) on all samples
FISblanks7lociall <- read.csv("FISblanks_7loci_allsamples.csv", sep=",", row.names=NULL)
FISblanks7lociall
with(FISblanks7lociall, cor.test(Nb, FIS, alternative="greater", method="spearman")) 

### Correlation between FIS and number of blanks for 4 loci (Gb 5, 35, 66, 73) on all samples
FISblanks4lociall <- read.csv("FISblanks_4loci_allsamples.csv", sep=",", row.names=NULL)
FISblanks4lociall
with(FISblanks4lociall, cor.test(Nb, FIS, alternative="greater", method="spearman")) 

```

```{r }
### Short allele dominance 
SAD <- read.csv("SAD.csv",sep=",", row.names=NULL)
SAD

SAD_Gb28 <- subset(SAD,loci=="Gb28")
SAD_Gb28
with(SAD_Gb28, cor.test(Allele, Capf, alternative="less", method="spearman"))


SAD_Gb35 <- subset(SAD,loci=="Gb35")
SAD_Gb35
with(SAD_Gb35, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb48 <- subset(SAD,loci=="Gb48")
SAD_Gb48
with(SAD_Gb48, cor.test(Allele, Capf, alternative="less", method="spearman"))
with(SAD_Gb48, cor.test(Smallf, Weights, alternative="less", method="spearman"))

lm_SAD_Gb48 <- lm(Smallf ~ Allele, data=SAD_Gb48, Weights=weight)
summary(lm_SAD_Gb48) 

SAD_Gb5 <- subset(SAD,loci=="Gb5")
SAD_Gb5
with(SAD_Gb5, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb66 <- subset(SAD,loci=="Gb66")
SAD_Gb66
with(SAD_Gb66, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb72 <- subset(SAD,loci=="Gb72")
SAD_Gb72
with(SAD_Gb72, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb158 <- subset(SAD,loci=="Gb158")
SAD_Gb158
with(SAD_Gb158, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb73 <- subset(SAD,loci=="Gb73")
SAD_Gb73
with(SAD_Gb73, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb92 <- subset(SAD,loci=="Gb92")
SAD_Gb92
with(SAD_Gb92, cor.test(Allele, Capf, alternative="less", method="spearman"))

SAD_Gb165 <- subset(SAD,loci=="Gb165")
SAD_Gb165
with(SAD_Gb165, cor.test(Allele, Capf, alternative="less", method="spearman"))

```

```{r }
### Linkage disequilibrium: BY correction for 9 selected loci
p.adjust(c(0.3265,	0.5193,	0.0006,	0.6329,	0.864,	0.7794,	0.821,	0.8735,	0.2963,	0.1097,	0.0085,	0.0715,	0.0115,
           0.081,	0.9701,	0.2031,	0.5426,	0.5946,	0.0201,	0.4044,	0.2177,	1,	0.3921,	0.5911,	0.269,	0.3584,	0.0654,
           0.4602,	0.5638,	0.8668,	0.4043,	0.3298,	0.8541,	0.4636,	0.8868,	0.6678), method="BY")

```

```{r }
### Correlation between FIS and FST for 9 selected loci on all samples
FISFST9loci <- read.csv("FISFST_9loci_allsamples.csv", sep=",", row.names=NULL)
FISFST9loci
with(FISFST9loci, cor.test(FST, FIS, alternative="greater", method="spearman"))

```

```{r }
### Correlation between FIS and FST for 9 selected loci on field samples only
FISFST9locifieldsamples <- read.csv("FISFST_9loci_fieldsamples.csv", sep=",", row.names=NULL)
FISFST9locifieldsamples
with(FISFST9locifieldsamples, cor.test(FST, FIS, alternative="greater", method="spearman"))

```

```{r }
### Correlation between FIS and number of blanks for selected 9 loci on field samples
FISblanks9loci_fieldsamples <- read.csv("FISblanks_9loci_fieldsamples.csv", sep=",", row.names=NULL)
FISblanks9loci_fieldsamples
with(FISblanks9loci_fieldsamples, cor.test(Nb, FIS, alternative="greater", method="spearman")) 

```

```{r }
### Correlation between FIS and number of blanks for loci without null alleles (Gb5, 35, 66, 73, 92)
FISblankslocinonulls_fieldsamples <- read.csv("FISblanks_locinonulls_fieldsamples.csv", sep=",", row.names=NULL)
FISblankslocinonulls_fieldsamples
with(FISblankslocinonulls_fieldsamples, cor.test(Nb, FIS_nulls, alternative="greater", method="spearman")) 

```
